{
 "nbformat": 4,
 "nbformat_minor": 2,
 "metadata": {
  "language_info": {
   "name": "python",
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "version": "3.7.5-final"
  },
  "orig_nbformat": 2,
  "file_extension": ".py",
  "mimetype": "text/x-python",
  "name": "python",
  "npconvert_exporter": "python",
  "pygments_lexer": "ipython3",
  "version": 3,
  "kernelspec": {
   "name": "python37564bit7864ce697006450d81c3f54dae018d4c",
   "display_name": "Python 3.7.5 64-bit",
   "language": "python"
  }
 },
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "with open('./original lists/word list1.txt', 'r') as f:\n",
    "    word_list = f.read()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "'challenge\\nfurnish\\nestablish\\nintellectual\\nqualification\\nappearance\\naspect\\nliquid\\nlad\\napply\\nexterior\\npreference\\nelbow\\ndiscipline\\nthrill\\nallegiance\\nedition\\ntriumph\\nhostage\\nloaf\\napplicable\\nmotion\\ndiploma\\ncontrast\\ntrend\\nhonourable\\nfreelance\\nappendix\\nobjection\\nsubstantial\\nhasty\\ninterpret\\nfraction\\nrectangle\\nowl\\ndenote\\neditor\\nfruitful\\nstartle\\ninlet\\nsystem\\nconcede\\ndictate\\nlame\\nexhaust\\nstiff\\npinch\\npants\\nremnant\\nprojector\\ntorrent\\ncrisp\\ntag\\nduration\\ndealer\\nincident\\nzeal\\nrhythm\\nrhyme\\neducate\\noverlook\\nshear\\nkidnap\\npropaganda\\nprescribe\\ncape\\n'"
     },
     "metadata": {},
     "execution_count": 2
    }
   ],
   "source": [
    "word_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "['challenge',\n 'furnish',\n 'establish',\n 'intellectual',\n 'qualification',\n 'appearance',\n 'aspect',\n 'liquid',\n 'lad',\n 'apply',\n 'exterior',\n 'preference',\n 'elbow',\n 'discipline',\n 'thrill',\n 'allegiance',\n 'edition',\n 'triumph',\n 'hostage',\n 'loaf',\n 'applicable',\n 'motion',\n 'diploma',\n 'contrast',\n 'trend',\n 'honourable',\n 'freelance',\n 'appendix',\n 'objection',\n 'substantial',\n 'hasty',\n 'interpret',\n 'fraction',\n 'rectangle',\n 'owl',\n 'denote',\n 'editor',\n 'fruitful',\n 'startle',\n 'inlet',\n 'system',\n 'concede',\n 'dictate',\n 'lame',\n 'exhaust',\n 'stiff',\n 'pinch',\n 'pants',\n 'remnant',\n 'projector',\n 'torrent',\n 'crisp',\n 'tag',\n 'duration',\n 'dealer',\n 'incident',\n 'zeal',\n 'rhythm',\n 'rhyme',\n 'educate',\n 'overlook',\n 'shear',\n 'kidnap',\n 'propaganda',\n 'prescribe',\n 'cape']"
     },
     "metadata": {},
     "execution_count": 3
    }
   ],
   "source": [
    "word_list.split()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "'challenge# #furnish# #establish# #intellectual# #qualification# #appearance# #aspect# #liquid# #lad# #apply# #exterior# #preference# #elbow# #discipline# #thrill# #allegiance# #edition# #triumph# #hostage# #loaf# #applicable# #motion# #diploma# #contrast# #trend# #honourable# #freelance# #appendix# #objection# #substantial# #hasty# #interpret# #fraction# #rectangle# #owl# #denote# #editor# #fruitful# #startle# #inlet# #system# #concede# #dictate# #lame# #exhaust# #stiff# #pinch# #pants# #remnant# #projector# #torrent# #crisp# #tag# #duration# #dealer# #incident# #zeal# #rhythm# #rhyme# #educate# #overlook# #shear# #kidnap# #propaganda# #prescribe# #cape'"
     },
     "metadata": {},
     "execution_count": 4
    }
   ],
   "source": [
    "word_join = '# #'.join(word_list.split())\n",
    "word_join"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "'#challenge# #furnish# #establish# #intellectual# #qualification# #appearance# #aspect# #liquid# #lad# #apply# #exterior# #preference# #elbow# #discipline# #thrill# #allegiance# #edition# #triumph# #hostage# #loaf# #applicable# #motion# #diploma# #contrast# #trend# #honourable# #freelance# #appendix# #objection# #substantial# #hasty# #interpret# #fraction# #rectangle# #owl# #denote# #editor# #fruitful# #startle# #inlet# #system# #concede# #dictate# #lame# #exhaust# #stiff# #pinch# #pants# #remnant# #projector# #torrent# #crisp# #tag# #duration# #dealer# #incident# #zeal# #rhythm# #rhyme# #educate# #overlook# #shear# #kidnap# #propaganda# #prescribe# #cape#'"
     },
     "metadata": {},
     "execution_count": 5
    }
   ],
   "source": [
    "word_join = '#' + word_join + '#'\n",
    "word_join"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os,sys\n",
    "\n",
    "PROJECT_ROOT_DIR = os.getcwd()\n",
    "PROCESSING_DIR = 'original lists'\n",
    "PRODUCED_DIR = 'regularized lists'\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "'/Users/rgmax/Desktop/FileBox/word list /original lists/test'"
      ]
     },
     "metadata": {},
     "execution_count": 8
    }
   ],
   "source": [
    "book_name = 'test'\n",
    "book_path = os.path.join(PROJECT_ROOT_DIR, PROCESSING_DIR, book_name)\n",
    "book_path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "metadata": {},
     "execution_count": 9
    }
   ],
   "source": [
    "os.path.exists(book_path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "def list_regularization(book_name, list_name):\n",
    "    print('-'*10 + ' Processing '+ '-'*10)\n",
    "    book_path = os.path.join(PROJECT_ROOT_DIR, PROCESSING_DIR, book_name)\n",
    "    if not os.path.exists(book_path):\n",
    "        print('vocabulary book does not exist!\\nProcess aborted.')\n",
    "        return \n",
    "    list_path = os.path.join(book_path, list_name)\n",
    "    with open(list_path, 'r') as f:\n",
    "        word_list = f.read()\n",
    "    word_join = '#' + '# #'.join(word_list.split())+ '#'\n",
    "    produced_book_path = os.path.join(PROJECT_ROOT_DIR, PRODUCED_DIR, book_name)\n",
    "    if not os.path.exists(produced_book_path):\n",
    "        os.mkdir(produced_book_path)\n",
    "    produced_list_path = os.path.join(produced_book_path, list_name)\n",
    "    with open(produced_list_path, 'w') as f:\n",
    "        f.write(word_join)\n",
    "    print('Process completed !')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "---------- Processing ----------\nvocabulary book does not exist!\nProcess aborted.\n"
     ]
    }
   ],
   "source": [
    "list_regularization('cet', 'list1')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ]
}